/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.star.modules.sys.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.sys.utils.DictUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.star.modules.sys.entity.ShHouse;
import com.star.modules.sys.service.ShHouseService;

/**
 * 房源信息Controller
 * @author L
 * @version 2018-09-04
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/shHouse")
public class ShHouseController extends BaseController {

	@Autowired
	private ShHouseService shHouseService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ShHouse get(String id, boolean isNewRecord) {
		return shHouseService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("sys:shHouse:view")
	@RequestMapping(value = {"list", ""})
	public String list(ShHouse shHouse, Model model) {
		model.addAttribute("shHouse", shHouse);
		return "modules/sys/shHouseList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("sys:shHouse:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ShHouse> listData(ShHouse shHouse, HttpServletRequest request, HttpServletResponse response) {
		Page<ShHouse> page = shHouseService.findPage(new Page<ShHouse>(request, response), shHouse); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("sys:shHouse:view")
	@RequestMapping(value = "form")
	public String form(ShHouse shHouse, Model model) {
		model.addAttribute("shHouse", shHouse);
		return "modules/sys/shHouseForm";
	}

	/**
	 * 保存房源信息
	 */
	@RequiresPermissions("sys:shHouse:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ShHouse shHouse) {
		shHouseService.save(shHouse);
		return renderResult(Global.TRUE, "保存房源信息成功！");
	}
	
	/**
	 * 停用房源信息
	 */
	@RequiresPermissions("sys:shHouse:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(ShHouse shHouse) {
		shHouse.setStatus(ShHouse.STATUS_DISABLE);
		shHouseService.updateStatus(shHouse);
		return renderResult(Global.TRUE, "停用房源信息成功");
	}
	
	/**
	 * 启用房源信息
	 */
	@RequiresPermissions("sys:shHouse:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(ShHouse shHouse) {
		shHouse.setStatus(ShHouse.STATUS_NORMAL);
		shHouseService.updateStatus(shHouse);
		return renderResult(Global.TRUE, "启用房源信息成功");
	}

	/**
	 * 启用房源信息
	 */
	@RequiresPermissions("sys:shHouse:edit")
	@RequestMapping(value = "ishot")
	@ResponseBody
	public String ishot(ShHouse shHouse) {
		shHouse.setIsHot(Boolean.TRUE);
		shHouseService.update(shHouse);
		return renderResult(Global.TRUE, "启用推荐成功");
	}

	/**
	 * 启用房源信息
	 */
	@RequiresPermissions("sys:shHouse:edit")
	@RequestMapping(value = "isnothot")
	@ResponseBody
	public String isnothot(ShHouse shHouse) {
		shHouse.setIsHot(Boolean.FALSE);
		shHouseService.update(shHouse);
		return renderResult(Global.TRUE, "取消推荐成功");
	}
	/**
	 * 删除房源信息
	 */
	@RequiresPermissions("sys:shHouse:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ShHouse shHouse) {
		shHouseService.delete(shHouse);
		return renderResult(Global.TRUE, "删除房源信息成功！");
	}
	
}